﻿using System;
using Common.Builders.Interfaces;
using Common.Entities;
using DataAccess.DAO;

namespace DataAccess.Converters
{
    public class UserAccountEntityConverter : IUserAccountEntityConverter
    {
        private readonly IUserAccountBuilder _userAccountBuilder;

        public UserAccountEntityConverter(IUserAccountBuilder userAccountBuilder)
        {
            _userAccountBuilder = userAccountBuilder;
        }

        public UserAccount ConvertToEntity(UserAccountDAO entityDao)
        {
            return _userAccountBuilder.WithUserAccountName(entityDao.AccountName.TrimEnd(' '))
                .WithUserAccountPassword(entityDao.AccountPassword.TrimEnd(' ')).Build();
        }

        public UserAccountDAO ConvertToEntityDAO(UserAccount entity)
        {
            return new UserAccountDAO {AccountName = entity.AccountName, AccountPassword = entity.AccountPassword};
        }
    }
}
